package com.aceitunaproject.server;

import java.util.LinkedList;
import java.util.List;

import com.aceitunaproject.server.equipment.EquipmentLoader;
import com.aceitunaproject.server.initializer.Initializer;
import com.aceitunaproject.server.initializer.TestEquipmentLoader;
import com.aceitunaproject.server.initializer.TestInitializer;
import com.aceitunaproject.server.initializer.TestInstallationTypeLoader;
import com.aceitunaproject.server.initializer.TestMaterialGoodsLoader;
import com.aceitunaproject.server.initializer.TestTerrainTypeLoader;
import com.aceitunaproject.server.installation.InstallationTypeLoader;
import com.aceitunaproject.server.materialgoods.MaterialGoodLoader;
import com.aceitunaproject.server.science.ScientificAdvanceLoader;
import com.aceitunaproject.server.terrain.TerrainTypeLoader;
import com.aceitunaproject.shared.message.AceitunaSender;
import com.aceitunaproject.shared.message.MessageSender;
import com.aceitunaproject.shared.message.MessageSenderImpl;
import com.aceitunaproject.shared.util.BinaryObjectSerializer;
import com.aceitunaproject.shared.util.ObjectSerializer;

/**
 * Server configuration class
 * 
 * TODO: add object serializer based on application props, consider using an
 * instance vs static accessor
 * 
 * TODO: get Handler map from configuration file.
 * 
 * TODO: get Initializer class from configuration file.
 * 
 * TODO: game parameters from configuration file
 * 
 * TODO: get MessageSender class from configuration file.
 * 
 * @author Maciej Miechowicz
 */
public class ServerConfiguration {

	// the initializer class to be used by the listener when the server is started
	private static Initializer initializer = new TestInitializer();

	private static ObjectSerializer serializer = new BinaryObjectSerializer();
	

	/**
	 * Returns object serializer to be used when (de)serializing objects to/from
	 * client
	 * 
	 * @return object serializer
	 */
	public static ObjectSerializer getObjectSerializer() {
		return serializer;
	}

	/**
	 * Returns the initializer class to be used by the AppListener when the server is started
	 * @return initializer class
	 */
	public static Initializer getInitializer() {
		return initializer;
	}
	
	/**
	 * Sets the initializer class to be used by the AppListener when the server is started
	 * 
	 */
	public static void SetInitializer(Initializer init) {
		initializer = init;
	}

	
	
	/**
	 * 
	 * Returns a MessageSender class wrapping the given AceitunaSender
	 * 
	 * @param sender
	 *            the AceitunaSender class to wrap
	 * @return the MessageSender
	 */
	public static MessageSender getMessageSender(AceitunaSender sender) {
		return new MessageSenderImpl(sender);

	}
	
	//GAME PARAMETERS
	
	/**
	 * Returns the minimum cost in TimeUnits to move an unit one tile.
	 */
	public static int getBasicMovementCost()
	{
		return 1; //TODO: get from configuration file
	}

	public static TerrainTypeLoader getTerrainTypeLoader() {
		
		//returns the test TerrainTypeLoader for now.
		return new TestTerrainTypeLoader();
		
	}

	public static EquipmentLoader getEquipmentLoader() {
		//returns the test EquipmentLoader for now.
		return new TestEquipmentLoader();
	}

	public static ScientificAdvanceLoader getScientificAdvanceLoader() {
		// TODO Auto-generated method stub
		return null;
	}

	public static InstallationTypeLoader getInstallationTypeLoader() {
		
		return new TestInstallationTypeLoader();
	}

	public static MaterialGoodLoader getMaterialGoodLoader() {
		return new TestMaterialGoodsLoader();
	}

	
	public static int getAttackingTimeUnitCost()
	{
		return 1;
	}
	
	
	
	public static int getInstallationPersonRate() {
		
		return 10;
	}

	public static int getFoodPersonRate() {
		// TODO get from configuration file
		return 1;
	}

	public static List<String> getFoodGoods() {

		List<String> retList = new LinkedList<String>();
		retList.add("Food");
		return retList;
	}

	public static int getSignificantFoodDifference() {
		// TODO Auto-generated method stub
		return 0;
	}

	public static int getHungerMoraleEffect() {
		// TODO Auto-generated method stub
		return 1;
	}

	public static int getFoodAbundanceMoraleEffect() {
		// TODO Auto-generated method stub
		return 1;
	}

	public static int getFoodPopulationEffect() {
		// TODO Auto-generated method stub
		return 1;
	}

	
}
